package com.bookshop.order.data;

import com.bookshop.dataOperator.DatabaseUtils;
import com.bookshop.order.state.OrderState;
import com.bookshop.pojo.OrderPOJO;
import com.bookshop.vo.OrdersVO;


public class Search implements OrderDBData{
	public OrdersVO list(int pBegin,int pEnd){
		OrderPOJO[] pojos = DatabaseUtils.getAllOrders(pBegin,pEnd);
		return PojosToVo.toVO(pojos);
	}

	public OrdersVO byId(String pId,int pBegin,int pEnd){
		String order = "select * from " + TABLE_NAME + " where " + COLUMNS[INDEX_ID] + "='" + pId + "'";
		OrderPOJO[] orderPOJOs = (OrderPOJO[]) DatabaseUtils.search(TABLE_NAME, order, pBegin, pEnd);
		return PojosToVo.toVO(orderPOJOs);
	}
	
	public OrdersVO byUser(String pUserAccount,int pBegin,int pEnd){
		String order = "select * from " + TABLE_NAME + " where " + COLUMNS[INDEX_USER] + "='" + pUserAccount + "'";
		OrderPOJO[] orderPOJOs = (OrderPOJO[]) DatabaseUtils.search(TABLE_NAME, order, pBegin, pEnd);
		return PojosToVo.toVO(orderPOJOs);
	}
	
	
	public OrdersVO byState(OrderState pOrderState,int pBegin,int pEnd){
		String order = "select * from " + TABLE_NAME + " where " + COLUMNS[INDEX_STATE] + "='" + pOrderState + "'";
		OrderPOJO[] orderPOJOs = (OrderPOJO[]) DatabaseUtils.search(TABLE_NAME, order, pBegin, pEnd);
		return PojosToVo.toVO(orderPOJOs);
	}
	
}
